package com.prd.controller;

import com.prd.dto.EntReportInstructDto;
import com.prd.model.EntReport;
import com.prd.service.EntReportService;
import com.prd.util.AjaxResult;
import com.prd.util.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "报告/汇报")
@RestController
@RequestMapping("/api/entReport")
public class EntReportController extends BaseController {

    @Autowired
    private EntReportService entReportService;

    @ApiOperation("查询列表")
    @GetMapping("list")
    public TableDataInfo list(@ApiParam("日期") String day, @ApiParam("1：汇报、2：报告") Integer type, @ApiParam("1:我发起、2：我接收、3：已批示、4：我编制") Integer form) {
        startPage();
        List<EntReport> list = entReportService.listInfo(day, type, form);
        return getDataPage(list);
    }

    @ApiOperation("添加信息")
    @PostMapping("add")
    public AjaxResult add(@RequestBody EntReport entReport) {
        return toAjax(entReportService.insertInfo(entReport));
    }

    @ApiOperation("修改信息")
    @PostMapping("update")
    public AjaxResult update(@RequestBody EntReport entReport) {
        return toAjax(entReportService.updateInfo(entReport));
    }

    @ApiOperation("查询详情")
    @GetMapping(value = "details/{id}")
    public AjaxResult details(@PathVariable("id") Long id) {
        return AjaxResult.success(entReportService.details(id));
    }

    @ApiOperation("增加抄送人")
    @PostMapping(value = "addMake/{reportId}/{makes}")
    public AjaxResult addMake(@ApiParam("汇报ID") @PathVariable("reportId") Long reportId, @ApiParam("抄送人（多个,分开）") @PathVariable("makes") Long[] makes) {
        return toAjax(entReportService.addMake(reportId, makes));
    }

    @ApiOperation("查询人员权限")
    @GetMapping("jurisdiction/{reportId}")
    public AjaxResult jurisdiction(@PathVariable("reportId") Long reportId) {
        return AjaxResult.success(entReportService.jurisdiction(reportId));
    }

    @ApiOperation("上传表态信息")
    @PostMapping("addDeclare")
    public AjaxResult addDeclare(@RequestBody EntReport entReport) {
        if (entReport.getId() == null || StringUtils.isBlank(entReport.getInstructDeclare())) {
            return AjaxResult.error("参数不能为空！");
        }
        return toAjax(entReportService.addDeclare(entReport.getId(), entReport.getInstructDeclare()));
    }

    @ApiOperation("上传执行/贯彻结果信息")
    @PostMapping("addExecute")
    public AjaxResult addExecute(@RequestBody EntReport entReport) {
        if (entReport.getId() == null || StringUtils.isBlank(entReport.getInstructExecute())) {
            return AjaxResult.error("参数不能为空！");
        }
        return toAjax(entReportService.addExecute(entReport.getId(), entReport.getInstructExecute()));
    }

    @ApiOperation("批示")
    @PostMapping("addInstruct")
    public AjaxResult addInstruct(@RequestBody EntReportInstructDto entReportInstructDto) {
        return toAjax(entReportService.addInstruct(entReportInstructDto));
    }

    @ApiOperation("再次批示")
    @PostMapping("addAgain")
    public AjaxResult addAgain(@RequestBody EntReportInstructDto entReportInstructDto) {
        return toAjax(entReportService.addAgain(entReportInstructDto));
    }
}
